package com.chaoXing.work2;



/*


    懒汉模式设计单例
    因为题目要求多次创建时要输出不同的返回信息

    如果饿汉式单例的话不符输出标准
 */
public class MyPrinter {

   private static MyPrinter myPrinter=null;

//    private static final MyPrinter myPrinter=new MyPrinter();
    private MyPrinter() {
        System.out.println("My type is Canon-ip110");
    }

    public static MyPrinter getMyPrinter(){
        if(myPrinter==null)
        {
            myPrinter=new MyPrinter();
        }
        else {
            System.out.println("I'm the only one.");
        }
        return myPrinter;
//        if(myPrinter!=null)
//        {
//            System.out.println("I'm the only one.");
//        }
//        return myPrinter;
    }

    public void print(Object o){
        System.out.println(o.toString());
    }


    @Override
    public String toString() {
        return "My type is Canon-ip110"+"\n"+"-----------------------";
    }
}
